package com.ming.luckyDemo.service.serviceImpl;

import com.ming.luckyDemo.mapper.RegisterMapper;
import com.ming.luckyDemo.pojo.DO.UserInfoDO;
import com.ming.luckyDemo.service.RegisterService;
import com.ming.luckyDemo.util.DateUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Tcm
 */
@Service
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    RegisterMapper registerMapper;

    @Override
    public void insertUser(UserInfoDO userInfoDO) {
        DateUtil dateUtil = new DateUtil();
        registerMapper.insertUser(userInfoDO.getUsername(),userInfoDO.getPassword(),userInfoDO.getEmail(), dateUtil.getCurrentTime());
    }

    @Override
    public UserInfoDO queryByName(String username) {
        return registerMapper.queryByName(username);
    }

    /**
     * 验证密码，以及更新sessionKey
     * @param userInfoDO
     */
    @Override
    public boolean login(UserInfoDO userInfoDO) {
        registerMapper.updateCookie(userInfoDO.getUsername(),userInfoDO.getSessionKey());
        UserInfoDO userInfoDO1 = registerMapper.queryByInfo(userInfoDO.getUsername(), userInfoDO.getPassword());
        if(userInfoDO1!=null){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public UserInfoDO login2(String cookieName) {
        return registerMapper.queryByName(cookieName);

    }
}
